package com.admin.oauth.dto;

import com.admin.core.entity.SysUser;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.List;
import java.util.Set;

/**
 * @author sq-lan
 */
@Getter
@AllArgsConstructor
public class LoginUserDto implements UserDetails {

    private final SysUser user;

    private final Set<Integer> dataScopes;

    private final List<GrantedAuthority> authorities;

    private final Set<String> permissions;

    /**
     * 给前端使用
     *
     * @return {@link Set}<{@link String}>
     */
    public Set<String> getRoles() {
        return permissions;
    }

    @Override
    @JSONField(serialize = false)
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    @JSONField(serialize = false)
    public String getUsername() {
        return user.getUsername();
    }

    @JSONField(serialize = false)
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JSONField(serialize = false)
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JSONField(serialize = false)
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    @JSONField(serialize = false)
    public boolean isEnabled() {
        return user.getEnabled();
    }

}
